// 基础路径 注意发布之前要先修改这里
const BASE_URL =
  process.env.NODE_ENV === "production" ? process.env.VUE_APP_ROOT_URL : "/";

/*const path = require('path')
function resolve(dir) {
  return path.join(__dirname, dir)
}*/

// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
  publicPath: BASE_URL, // 根据你的实际情况更改这里
  lintOnSave: process.env.NODE_ENV === "development",
  productionSourceMap: false,
  transpileDependencies: ["@jiaminghi", "@microsoft/signalr"],

  configureWebpack: () => {
    if (process.env.NODE_ENV !== "development") {
      return {
        performance: {
          hints: false,
          maxEntrypointSize: 512000,
          maxAssetSize: 512000,
        },
      };
    }
  },
  // configureWebpack: config => {
  //     if (process.env.NODE_ENV === 'production') {
  //         return {
  //             plugins: [
  //                 new BundleAnalyzerPlugin()
  //             ]
  //         }
  //     }
  // },
  chainWebpack: (config) => {
    config.plugins.delete("preload");
    config.plugins.delete("prefetch");
    // 配置cdn引入
    /*config.plugin('html').tap((args) => {
      args[0].cdn = cdn;
      return args
    }) */

    //忽略的打包文件
    config.externals({
      vue: "Vue",
      "vue-router": "VueRouter",
      vuex: "Vuex",
      axios: "axios",
      "element-ui": "ELEMENT",
    });

    /*config
      .when(process.env.NODE_ENV !== 'development',
        config => {
          config
            .optimization.splitChunks({
              chunks: 'all',
              cacheGroups: {
                vendor: {
                  minChunks:1,
                  minSize:1,
                  chunks: 'all',
                  name: 'chunk-setting',
                  test: resolve('src/config'), // can customize your rules
                }
              }
            })
        }
      )*/

    const entry = config.entry("app");
    entry.add("babel-polyfill").end();
    entry.add("classlist-polyfill").end();
    /*entry
      .add('@/mock')
      .end()*/
  },
  devServer: {
    open: true,
    port: 2125,
  },
};
